package com.sx.micowell.module.user.writeInfo

import android.annotation.SuppressLint
import android.app.AlertDialog
import android.app.DatePickerDialog
import android.icu.util.Calendar
import android.widget.RadioButton
import android.widget.Toast
import androidx.core.view.forEach
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.example.mvvm.base.data.DataBindingConfig
import com.example.mvvm.until.ToastUtils
import com.gyf.immersionbar.ImmersionBar
import com.sx.micowell.BR
import com.sx.micowell.R
import com.sx.micowell.databinding.ActSelectSexAgeBinding
import com.sx.micowell.framework.app.MyActivity
import com.sx.micowell.framework.arouth.RouteManager
import com.sx.micowell.framework.arouth.RoutePath
import com.sx.micowell.framework.model.PhysicalInfoModel


/**
 * @Author: YY
 * @Time: 2021/8/31
 * @Describe TODO
 */
@Route(path = RoutePath.WRITE_SEX_AGE)
class WriteSexAgeActivity : MyActivity<ActSelectSexAgeBinding>() {
    private var mYear: Int = 0
    private var mMonth: Int = 0
    private var mDay: Int = 0
    private var selectDate: Boolean = false

    // 0 男 1 女
    private var selectSex = "0"

    private var viewMode: PhysicalInfoModel? = null

    override fun getDataBindingConfig(): DataBindingConfig {
        return DataBindingConfig(R.layout.act_select_sex_age, BR.viewModel, viewMode)
    }

    override fun initViewModel() {
        super.initViewModel()
        viewMode = getActivityScopeViewModel(PhysicalInfoModel::class.java)
    }

    @SuppressLint("SetTextI18n")
    override fun initView() {
        ImmersionBar.with(this).statusBarDarkFont(true)
            .fitsSystemWindows(true).init()

        // 出生年月
        val ca: Calendar = Calendar.getInstance()
        mYear = ca.get(Calendar.YEAR)
        mMonth = ca.get(Calendar.MONTH)
        mDay = ca.get(Calendar.DAY_OF_MONTH)
        binding.tvSelectDate.setOnClickListener {
            DatePickerDialog(this, AlertDialog.THEME_HOLO_LIGHT, { view, year, month, dayOfMonth ->
                binding.tvSelectDate.text = "${year}-${month}-${dayOfMonth}"
                selectDate = true
            }, mYear, mMonth, mDay).show()
        }

        // 下一步
        binding.tvNext.setOnClickListener {
            if (binding.rgBoy.isChecked) {
                selectSex = "0"
            } else if (binding.rgGirl.isChecked) {
                selectSex = "1"
            }
            if (!selectDate) {
                ToastUtils.showShort("请选择出生日期")
                return@setOnClickListener
            }
            RouteManager.getInstance()
                .intentToHeight(selectSex, binding.tvSelectDate.text.toString())
        }
    }

    override fun initData() {

    }
}